using System;
using System.Collections.Generic;
using System.Net.Http;
using Sustainalytics.ESGComputing.Service.Tests.GovernanceUnitTests.Fixtures;
using Sustainalytics.ESGRatings.Computing.Entities;
using Sustainalytics.ESGRatings.Computing.Entities.Governance;
using Sustainalytics.ESGRatings.DataContract;

namespace Sustainalytics.ESGComputing.Service.Tests.GovernanceUnitTests
{
    public sealed class GovernanceGivenExcelFixture : BaseGovernanceFixture
    {

        private readonly Guid[] _companyIds = {
            new Guid("00000000-0000-0000-0000-000000000003"),
        };

        private bool _disposed;

        public GovernanceGivenExcelFixture()
        {
            DataSet = new GovernanceDataContainer
            {
                SetId = SetId,
                IndicatorTemplates = GetIndicatorTemplates(),
                Companies = GetCompanies(),
                CompaniesRawScores = GetCompaniesRawScores(),
                Modifiers = GetCombinationModifiers(),
                WeightMatrix = GetWeightsMatrix()
            };



            HttpResponseMessage result;
            using (var taskAsync = SutClient.PostAsync(DataSet))
            {
                result = taskAsync.Result;
            }

            if (!result.IsSuccessStatusCode)
            {
                Console.Write(result.StatusCode);
            }

        }

        ~GovernanceGivenExcelFixture()
        {
            Dispose(false);
        }

        public GovernanceDataContainer DataSet { get; private set; }

        public override Guid MatrixId
        {
            get
            {
                return
                    new Guid("00000000-0000-0000-0000-000000000002");
            }
        }



        public override Guid SetId
        {
            get { return new Guid("00000000-0000-0000-0000-000000000012"); }
        }




        protected override void Dispose(bool disposing)
        {
            if (_disposed)
                return;

            if (disposing)
            {

                try
                {
                    var taskClean = SutClient.DeleteAsync(SetId);
                    taskClean.Result.EnsureSuccessStatusCode();
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    SutClient.Dispose();
                }

            }
            _disposed = true;
        }
        protected override ICollection<CombinationModifier> GetCombinationModifiers()
        {
            return new List<CombinationModifier>
            {
                //G.1
                new CombinationModifier("G.1.1","G.1.2",0.3f),
                new CombinationModifier("G.1.3","G.1.6",0.3f),
                new CombinationModifier("G.1.3","G.1.8",0.1f),
                new CombinationModifier("G.1.3","G.1.9",0.1f),
                new CombinationModifier("G.1.3","G.1.10",0.1f),
                new CombinationModifier("G.1.8","G.1.9",0.2f),
                new CombinationModifier("G.1.8","G.1.10",0.2f),
                new CombinationModifier("G.1.9","G.1.10",0.2f),

                //G.2
                new CombinationModifier("G.2.1","G.2.3",0.2f),
                new CombinationModifier("G.2.2","G.2.9",0.2f),
                new CombinationModifier("G.2.6","G.2.7",0.1f),
                new CombinationModifier("G.2.6","G.2.8",0.1f),


                //G.3
                new CombinationModifier("G.3.1","G.3.6",0.2f),
                new CombinationModifier("G.3.5","G.3.6",0.2f), 
                
                //G.4
                new CombinationModifier("G.4.7","G.4.8",0.2f),
                new CombinationModifier("G.4.8","G.4.9",0.25f),
                new CombinationModifier("G.4.10","G.4.13",0.2f),


                new CombinationModifier("G.5.5","G.5.6",0.3f),
                new CombinationModifier("G.5.2","G.5.7",0.2f),



            };
        }

        protected override ICollection<CompanyData> GetCompanies()
        {
            return new List<CompanyData>
            {
                new CompanyData( _companyIds[0],"Banks","EUR"),
            };
        }

        protected override ICollection<CompanyScores> GetCompaniesRawScores()
        {
            return new List<CompanyScores>
            {
                new CompanyScores(_companyIds[0], new List<IndicatorDefaultScore>
                {
                    new IndicatorDefaultScore("G.1.1"       ,60),
                    new IndicatorDefaultScore("G.1.2"       ,10),
                    new IndicatorDefaultScore("G.1.3"       ,60),
                    new IndicatorDefaultScore("G.1.4"       ,80),
                    new IndicatorDefaultScore("G.1.5"       ,90),
                    new IndicatorDefaultScore("G.1.6"       ,80),
                    new IndicatorDefaultScore("G.1.7"       ,40),
                    new IndicatorDefaultScore("G.1.8"       ,50),
                    new IndicatorDefaultScore("G.1.9"       ,0),
                    new IndicatorDefaultScore("G.1.10"      ,50),
                    new IndicatorDefaultScore("G.2.1"       ,40),
                    new IndicatorDefaultScore("G.2.2"       ,100),
                    new IndicatorDefaultScore("G.2.3"       ,60),
                    new IndicatorDefaultScore("G.2.4"       ,20),
                    new IndicatorDefaultScore("G.2.5"       ,50),
                    new IndicatorDefaultScore("G.2.6"       ,90),
                    new IndicatorDefaultScore("G.2.7"       ,60),
                    new IndicatorDefaultScore("G.2.8"       ,50),
                    new IndicatorDefaultScore("G.2.9"       ,50),
                    new IndicatorDefaultScore("G.2.10"      ,50),
                    new IndicatorDefaultScore("G.3.1"       ,0),
                    new IndicatorDefaultScore("G.3.2"       ,80),
                    new IndicatorDefaultScore("G.3.3"       ,40),
                    new IndicatorDefaultScore("G.3.4"       ,20),
                    new IndicatorDefaultScore("G.3.5"       ,80),
                    new IndicatorDefaultScore("G.3.6"       ,30),
                    new IndicatorDefaultScore("G.3.7"       ,0),
                    new IndicatorDefaultScore("G.3.8"       ,50),
                    new IndicatorDefaultScore("G.4.1"       ,30),
                    new IndicatorDefaultScore("G.4.2"       ,90),
                    new IndicatorDefaultScore("G.4.3"       ,90),
                    new IndicatorDefaultScore("G.4.4"       ,80),
                    new IndicatorDefaultScore("G.4.5"       ,30),
                    new IndicatorDefaultScore("G.4.6"       ,20),
                    new IndicatorDefaultScore("G.4.7"       ,70),
                    new IndicatorDefaultScore("G.4.8"       ,70),
                    new IndicatorDefaultScore("G.4.9"       ,50),
                    new IndicatorDefaultScore("G.4.10"      ,30),
                    new IndicatorDefaultScore("G.4.11"      ,80),
                    new IndicatorDefaultScore("G.4.12"      ,10),
                    new IndicatorDefaultScore("G.4.13"      ,100),
                    new IndicatorDefaultScore("G.5.1"       ,70),
                    new IndicatorDefaultScore("G.5.2"       ,70),
                    new IndicatorDefaultScore("G.5.3"       ,60),
                    new IndicatorDefaultScore("G.5.4"       ,40),
                    new IndicatorDefaultScore("G.5.5"       ,80),
                    new IndicatorDefaultScore("G.5.6"       ,10),
                    new IndicatorDefaultScore("G.5.7"       ,10),
                    new IndicatorDefaultScore("G.6.1"       ,80),
                    new IndicatorDefaultScore("G.6.2"       ,20),
                    new IndicatorDefaultScore("G.6.3"       ,30),
                    new IndicatorDefaultScore("G.6.4"       ,80),
                    new IndicatorDefaultScore("G.6.5"       ,90),
                    new IndicatorDefaultScore("G.6.6"       ,50),
                    new IndicatorDefaultScore("G.6.7"       ,60),
                    new IndicatorDefaultScore("G.6.8"       ,100),
                    new IndicatorDefaultScore("G.6.9"       ,50),
                    new IndicatorDefaultScore("G.6.10"      ,70),
                    new IndicatorDefaultScore("G.6.11"      ,50),
                }),
            };
        }

        protected override ICollection<IndicatorTemplate> GetIndicatorTemplates()
        {
            return new List<IndicatorTemplate>
            {
                new IndicatorTemplate("G.1.1","G","G.1"),
                new IndicatorTemplate("G.1.2","G","G.1"),
                new IndicatorTemplate("G.1.3","G","G.1"),
                new IndicatorTemplate("G.1.4","G","G.1"),
                new IndicatorTemplate("G.1.5","G","G.1"),
                new IndicatorTemplate("G.1.6","G","G.1"),
                new IndicatorTemplate("G.1.7","G","G.1"),
                new IndicatorTemplate("G.1.8","G","G.1"),
                new IndicatorTemplate("G.1.9","G","G.1"),
                new IndicatorTemplate("G.1.10","G","G.1"),

                new IndicatorTemplate("G.2.1","G","G.2") ,
                new IndicatorTemplate("G.2.2","G","G.2") ,
                new IndicatorTemplate("G.2.3","G","G.2") ,
                new IndicatorTemplate("G.2.4","G","G.2") ,
                new IndicatorTemplate("G.2.5","G","G.2") ,
                new IndicatorTemplate("G.2.6","G","G.2") ,
                new IndicatorTemplate("G.2.7","G","G.2") ,
                new IndicatorTemplate("G.2.8","G","G.2") ,
                new IndicatorTemplate("G.2.9","G","G.2") ,
                new IndicatorTemplate("G.2.10","G","G.2"),

                new IndicatorTemplate("G.3.1","G","G.3"),
                new IndicatorTemplate("G.3.2","G","G.3"),
                new IndicatorTemplate("G.3.3","G","G.3"),
                new IndicatorTemplate("G.3.4","G","G.3"),
                new IndicatorTemplate("G.3.5","G","G.3"),
                new IndicatorTemplate("G.3.6","G","G.3"),
                new IndicatorTemplate("G.3.7","G","G.3"),
                new IndicatorTemplate("G.3.8","G","G.3"),

                new IndicatorTemplate("G.4.1","G","G.4"),
                new IndicatorTemplate("G.4.2","G","G.4"),
                new IndicatorTemplate("G.4.3","G","G.4"),
                new IndicatorTemplate("G.4.4","G","G.4"),
                new IndicatorTemplate("G.4.5","G","G.4"),
                new IndicatorTemplate("G.4.6","G","G.4"),
                new IndicatorTemplate("G.4.7","G","G.4"),
                new IndicatorTemplate("G.4.8","G","G.4"),
                new IndicatorTemplate("G.4.9","G","G.4"),
                new IndicatorTemplate("G.4.10","G","G.4"),
                new IndicatorTemplate("G.4.11","G","G.4"),
                new IndicatorTemplate("G.4.12","G","G.4"),
                new IndicatorTemplate("G.4.13","G","G.4"),

                new IndicatorTemplate("G.5.1","G","G.5"),
                new IndicatorTemplate("G.5.2","G","G.5"),
                new IndicatorTemplate("G.5.3","G","G.5"),
                new IndicatorTemplate("G.5.4","G","G.5"),
                new IndicatorTemplate("G.5.5","G","G.5"),
                new IndicatorTemplate("G.5.6","G","G.5"),
                new IndicatorTemplate("G.5.7","G","G.5"),

                new IndicatorTemplate("G.6.1","G","G.6"),
                new IndicatorTemplate("G.6.2","G","G.6"),
                new IndicatorTemplate("G.6.3","G","G.6"),
                new IndicatorTemplate("G.6.4","G","G.6"),
                new IndicatorTemplate("G.6.5","G","G.6"),
                new IndicatorTemplate("G.6.6","G","G.6"),
                new IndicatorTemplate("G.6.7","G","G.6"),
                new IndicatorTemplate("G.6.8","G","G.6"),
                new IndicatorTemplate("G.6.9","G","G.6"),
                new IndicatorTemplate("G.6.10","G","G.6"),
                new IndicatorTemplate("G.6.11","G","G.6"),

            };
        }

        protected override RegionMatrix GetWeightsMatrix()
        {
            return new RegionMatrix
            {
                MatrixId = MatrixId,
                IssuesWeights = new List<IssuesWeights>
                {
                    new IssuesWeights("EUR", new List<IndicatorData<float>>
                    {
                        new IndicatorData<float>("G.1", 0.2f),
                        new IndicatorData<float>("G.2", 0.2f),
                        new IndicatorData<float>("G.3", 0.3f),
                        new IndicatorData<float>("G.4", 0.1f),
                        new IndicatorData<float>("G.5", 0.1f),
                        new IndicatorData<float>("G.6", 0.1f)

                    }),

                },
                Matrix = new List<RegionWeights>
                {
                    new RegionWeights("EUR", new List<IndicatorData<float>>
                    {
                        new IndicatorData<float>("G.1.1"    ,0.1f ),
                        new IndicatorData<float>("G.1.2"    ,0.1f ),
                        new IndicatorData<float>("G.1.3"    ,0.1f),
                        new IndicatorData<float>("G.1.4"    ,0.1f ),
                        new IndicatorData<float>("G.1.5"    ,0.1f ),
                        new IndicatorData<float>("G.1.6"    ,0.1f ),
                        new IndicatorData<float>("G.1.7"    ,0.1f ),
                        new IndicatorData<float>("G.1.8"    ,0.1f ),
                        new IndicatorData<float>("G.1.9"    ,0.1f ),
                        new IndicatorData<float>("G.1.10"   ,0.1f ),
                        new IndicatorData<float>("G.2.1"    ,0.1f        ),
                        new IndicatorData<float>("G.2.2"    ,0.1f        ),
                        new IndicatorData<float>("G.2.3"    ,0.1f        ),
                        new IndicatorData<float>("G.2.4"    ,0.1f        ),
                        new IndicatorData<float>("G.2.5"    ,0.1f        ),
                        new IndicatorData<float>("G.2.6"    ,0.1f        ),
                        new IndicatorData<float>("G.2.7"    ,0.1f        ),
                        new IndicatorData<float>("G.2.8"    ,0.1f        ),
                        new IndicatorData<float>("G.2.9"    ,0.1f        ),
                        new IndicatorData<float>("G.2.10"   ,0.1f        ),
                        new IndicatorData<float>("G.3.1"    ,0.125f      ),
                        new IndicatorData<float>("G.3.2"    ,0.125f      ),
                        new IndicatorData<float>("G.3.3"    ,0.125f      ),
                        new IndicatorData<float>("G.3.4"    ,0.125f      ),
                        new IndicatorData<float>("G.3.5"    ,0.125f      ),
                        new IndicatorData<float>("G.3.6"    ,0.125f      ),
                        new IndicatorData<float>("G.3.7"    ,0.125f      ),
                        new IndicatorData<float>("G.3.8"    ,0.125f      ),
                        new IndicatorData<float>("G.4.1"    ,0.076923077f),
                        new IndicatorData<float>("G.4.2"    ,0.076923077f),
                        new IndicatorData<float>("G.4.3"    ,0.076923077f),
                        new IndicatorData<float>("G.4.4"    ,0.076923077f),
                        new IndicatorData<float>("G.4.5"    ,0.076923077f),
                        new IndicatorData<float>("G.4.6"    ,0.076923077f),
                        new IndicatorData<float>("G.4.7"    ,0.076923077f),
                        new IndicatorData<float>("G.4.8"    ,0.076923077f),
                        new IndicatorData<float>("G.4.9"    ,0.076923077f),
                        new IndicatorData<float>("G.4.10"   ,0.076923077f),
                        new IndicatorData<float>("G.4.11"   ,0.076923077f),
                        new IndicatorData<float>("G.4.12"   ,0.076923077f),
                        new IndicatorData<float>("G.4.13"   ,0.076923077f),
                        new IndicatorData<float>("G.5.1"    ,0.142857143f),
                        new IndicatorData<float>("G.5.2"    ,0.142857143f),
                        new IndicatorData<float>("G.5.3"    ,0.142857143f),
                        new IndicatorData<float>("G.5.4"    ,0.142857143f),
                        new IndicatorData<float>("G.5.5"    ,0.142857143f),
                        new IndicatorData<float>("G.5.6"    ,0.142857143f),
                        new IndicatorData<float>("G.5.7"    ,0.142857143f),
                        new IndicatorData<float>("G.6.1"    ,0.090909091f),
                        new IndicatorData<float>("G.6.2"    ,0.090909091f),
                        new IndicatorData<float>("G.6.3"    ,0.090909091f),
                        new IndicatorData<float>("G.6.4"    ,0.090909091f),
                        new IndicatorData<float>("G.6.5"    ,0.090909091f),
                        new IndicatorData<float>("G.6.6"    ,0.090909091f),
                        new IndicatorData<float>("G.6.7"    ,0.090909091f),
                        new IndicatorData<float>("G.6.8"    ,0.090909091f),
                        new IndicatorData<float>("G.6.9"    ,0.090909091f),
                        new IndicatorData<float>("G.6.10"   ,0.090909091f),
                        new IndicatorData<float>("G.6.11"   ,0.090909091f),

                    }),

                }
            };
        }
    }
}